package org.dllwh.mysql.config;

import jakarta.annotation.Resource;
import org.jasypt.encryption.StringEncryptor;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

@Component
public class EncryptConfig implements CommandLineRunner {
    @Resource
    private ApplicationContext applicationContext;

    @Override
    public void run(String... args) throws Exception {
        Environment environment = applicationContext.getBean(Environment.class);
        // 获取配置文件中数据库用户名和密码的原始明文。
        String oldUrl = environment.getProperty("spring.datasource.url");
        String oldUserName = environment.getProperty("spring.datasource.username");
        String oldPassword = environment.getProperty("spring.datasource.password");

        // 打印加密前后的结果对比
        System.out.println("MySQL原始明文链接地址为：" + oldUrl);
        System.out.println("MySQL原始明文账号为：" + oldUserName);
        System.out.println("MySQL原始明文密码为：" + oldPassword);
    }
}
